<script type="text/javascript">
	function doSearchCmsContent(value) {
		
	}
	
	//表格查询  
	function reloadCmsContent() {
		var params = cmsContent_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		cmsContent_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		cmsContent_list.datagrid('unselectAll');
		cmsContent_list.datagrid('uncheckAll');
	}


	function addCmsContent() {
// 		createFromWindow("新增信息", "cmsContent.do?editCmsContent", "cmsContent.do?saveCmsContent",
// 				function(data) {
// 					reloadCmsContent();
// 				},true,1250,600);
		printLog(document.body.clientWidth+','+document.body.clientHeight);
		createFromWindowOptions({
			title:"新增信息",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			href:"cmsContent.do?editCmsContent",
			callback:function(d) {
				var rowData2 = d.form("getData");
				var ckData = CKEDITOR.instances.cmsContentTxt.getData();
				var formData = d.form("getData");
				formData.contentTxt = ckData;
				var uploadImgName = "";
				var selectTitleImg = "";
				$("input[name='uploadImgName']").each(function(){
			         uploadImgName += ','+jQuery(this).val();
			         var checkTitleImgId = 'seltype0'+jQuery(this).attr("index");
			         printLog($('#'+checkTitleImgId).attr("checked"));
			         if($('#'+checkTitleImgId).attr("checked")) {
			        	 selectTitleImg = jQuery(this).val();
			         }
				});
				
				var attPaths = "";
				var attNames = "";
				$("input[name='attPaths']").each(function(){
					attPaths += ','+jQuery(this).val();
					attNames += ','+jQuery(this).attr('fileName');
				});
				formData.attNames = attNames;
				formData.attPaths = attPaths;
				formData.selectTitleImg = selectTitleImg;
				formData.uploadImgName = uploadImgName;
				printLog(formData);
				$.ajax({
	           	  type: 'POST',
	           	  url: "cmsContent.do?saveCmsContent",
	              dataType : 'json',  
	           	  data: formData,
	           	  success: function(data) {
	           		  showMsg(data.msg);
	           		  if(data.success) {
	           			reloadCmsContent();
		           	  }
	           	  },
		          error:function(data,textstatus){  
		        	  printLog(data);
		        	  showMsg('请求异常');
		           }  
	           	});
				
			},
			enableSaveButton:true
		});
	}
	
	function deleteCmsContent() {
		var rows = cmsContent_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('cmsContent.do?deleteCmsContentItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadCmsContent();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editCmsContent() {
		var rows = cmsContent_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			editCommContent(rows[0].id);
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	function editCommContent(id) {
		createFromWindowOptions({
			title:"编辑信息",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			href:"cmsContent.do?editCmsContent&cmsContentId=" + id,
			callback:function(d) {
				var rowData2 = d.form("getData");
				var ckData = CKEDITOR.instances.cmsContentTxt.getData();
				var formData = d.form("getData");
				formData.contentTxt = ckData;
				var uploadImgName = "";
				var selectTitleImg = "";
				
				$("input[name='uploadImgName']").each(function(){
			         uploadImgName += ','+jQuery(this).val();
			         printLog(jQuery(this).attr("index"));
			         var checkTitleImgId = 'seltype0'+jQuery(this).attr("index");
			         printLog($('#'+checkTitleImgId).attr("checked"));
			         if($('#'+checkTitleImgId).attr("checked")) {
			        	 selectTitleImg = jQuery(this).val();
			         }
				});
				
				var attPaths = "";
				var attNames = "";
				$("input[name='attPaths']").each(function(){
					attPaths += ','+jQuery(this).val();
					attNames += ','+jQuery(this).attr('fileName');
				});
				formData.attNames = attNames;
				formData.attPaths = attPaths;
				formData.uploadImgName = uploadImgName;
				formData.selectTitleImg = selectTitleImg;
				printLog(formData);
				$.ajax({
	           	  type: 'POST',
	           	  url: "cmsContent.do?saveCmsContent",
	              dataType : 'json',  
	           	  data: formData,
	           	  success: function(data) {
	           		  showMsg(data.msg);
	           		  if(data.success) {
	           			reloadCmsContent();
		           	  }
	           	  },
		          error:function(data,textstatus){  
		        	  printLog(data);
		        	  showMsg('请求异常');
		           }  
	           	});
				
			},
			enableSaveButton:true
		});
	}
	
	
	function clearCmsContentSearch() {
		setGridSearchParams('cmsContent_list','cmsContentSearchForm',true,reloadCmsContent);
	}
	
	//根据条件查询
	function cmsContentSearch() {
		setGridSearchParams('cmsContent_list','cmsContentSearchForm',false,reloadCmsContent);
	}
	
	function onDblClickCmsContentRow(rowIndex, rowData) {
		editCommContent(rowData.id)
	}
	
	function createCmsContentSite() {
		$.ajax({
       	  type: 'POST',
       	  url: "cmsContent.do?createCmsContentSite&httpUrl=http://www.buysaas.cn",
          dataType : 'json',  
       	  data: {},
       	  success: function(data) {
       		  showMsg(data.msg);
       	  },
          error:function(data,textstatus){  
       	  	printLog(data);
       	  	showMsg('请求异常');
          }  
       	});
	}
</script>


<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="cmsContent_list" toolbar="#cmsContentlist_search" idField="id"  url="cmsContent.do?loadList" rownumbers="true" onDblClickRow="onDblClickCmsContentRow(rowIndex, rowData)"
			 item="com.xdtech.cms.vo.CmsContentItem"/>
		
		<div id="cmsContentlist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="cmsContentSearchForm">
					<!-- 防止form表单里只有一个text元素时候，按enter键自动提交问题 -->
					<input style="display:none" />
					<table>
						<tr>
							<td>标题：</td>
							<td><input class="easyui-validatebox textbox" name="title" style="width: 150px"/></td>
							<td>
								<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="cmsContentSearch()"/>
	 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearCmsContentSearch()"/>
 					 		</td>
						</tr>
					</table>
				</form>
				
			</div>
			<div id="cmsContent_toolbar" style="height: auto">
				<@eu.linkbutton showName="新增" shiro="cms:cmsContent:add" iconCls="icon-add" onclick="addCmsContent()"/>
				<@eu.linkbutton showName="删除" shiro="cms:cmsContent:delete" iconCls="icon-remove" onclick="deleteCmsContent()"/>
				<@eu.linkbutton showName="编辑" shiro="cms:cmsContent:edit" iconCls="icon-edit" onclick="editCmsContent()"/>
				<@eu.linkbutton showName="生成site文件" shiro="cms:cmsContent:createSite" iconCls="icon-reload" onclick="createCmsContentSite()"/>
				<@eu.linkbutton showName="刷新" shiro="cms:cmsContent:refresh" iconCls="icon-reload" onclick="reloadCmsContent()"/>
			</div>
		</div>
	</div>
</div>